/*
 * symboltable.h
 *
 *  Created on: Jan 14, 2014
 *      Author: Benjamin Groeber, Julian Sanin, Matthaeus Ranigler
 */

#ifndef SYMBOLTABLE_H_
#define SYMBOLTABLE_H_

#include "uthash.h"

typedef enum DataType {
	INT32,
	FP32,
	NAN /* Not a number */
} data_type_t;

typedef union DataValue {
	int int32;
	float fp32;
} data_value_t;

/*
 * .=============SYMBOL==============.
 * | ["SCOPE_LEVEL" + "SYMBOL_NAME"] | (Hash Key)
 * | [          DATA_TYPE          ] | Scope level: [0..MAX_INT], 0 = main
 * | [         DATA_VALUE          ] | Symbol name: [a-zA-Z]([a-zA-Z]|[0-9])*
 * | [       UT_HASH_HANDLE        ] |
 * ´=================================`
 */
typedef struct Symbol {
	char *name;
	data_type_t type;
	data_value_t value;
	UT_hash_handle hh;
} symbol_t;

/* Adds an integer value to the symbol table. */
void addSymbolInt32(char *symbolName, int scopeLevel, int value);

/* Adds an float value to the symbol table. */
void addSymbolFP32(char *symbolName, int scopeLevel, float value);

/* Finds a symbol in the symbol table.
 * Returns NULL if not found in this scope or parent scope. */
symbol_t *findSymbol(char *symbolName, int scopeLevel);

/* Removes all symbols of given scope depth from the symbol table. */
void removeAllSymbolsFromScopeLevel(int scopeLevel);

/* Removes all symbols from the symbol table. */
void removeAllSymbols();

/* Quick fix */
int decodeScopeLevel(const char *symbolName);

void printAllSymbols();

#endif /* SYMBOLTABLE_H_ */
